' This script shows how to determine if a layer is a text layer and
' how to apply to filter to a selection on the layer.
' The text layer must be rasterized before applying filters to it.
' Before running the script, create one or more text layers in the
' active document

Private Sub Command1_Click()

Dim appRef As Photoshop.Application
Dim docRef As Photoshop.Document
Dim textItemRef As Photoshop.TextItem
Dim artLayerRef As Photoshop.ArtLayer
Dim theOrigin As Variant
Dim theRasterizeType As Photoshop.PsRasterizeType
Dim selectionType As Photoshop.PsSelectionType
Dim rippleSize As Photoshop.PsRippleSize
Dim boxWidth As Long
Dim boxHeight As Long

Set appRef = New Photoshop.Application

If (appRef.Documents.Count > 0) Then

    Set docRef = appRef.ActiveDocument
    
    theRasterizeType = psEntireLayer
    selectionType = psReplaceSelection
    rippleSize = psLargeRipple
    
    For Each artLayerRef In docRef.ArtLayers
    
        If (artLayerRef.Kind = psTextLayer) Then
            docRef.ActiveLayer = artLayerRef
            
            ' must set the text kind to paragraph because you can only get the bounds of paragraph text.
            artLayerRef.TextItem.Kind = psParagraphText
                        
            theOrigin = artLayerRef.TextItem.Position
            boxWidth = artLayerRef.TextItem.Width
            boxHeight = artLayerRef.TextItem.Height
            
            'Select the Text Art.
            'The origin takes the justification into account, so no need to test
            'if right/left/center justified.
            docRef.Selection.Select Array(Array(theOrigin(0), theOrigin(1)), Array(boxWidth + theOrigin(0), theOrigin(1)), Array(boxWidth + theOrigin(0), theOrigin(1) + boxHeight), Array(theOrigin(0), theOrigin(1) + boxHeight)), Type:=selectionType, Feather:=0, AntiAlias:=False
            
            ' must rasterisze text items before applying filters to them.
            artLayerRef.Rasterize theRasterizeType
            artLayerRef.ApplyRipple amount:=150, Size:=rippleSize
            
            artLayerRef.ApplyStyle ("Overspray (Text)")
            docRef.Selection.Deselect
        End If
    Next
End If


End Sub
